/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.mwas.proteana.math.numerical;

import java.math.BigDecimal;
import java.math.RoundingMode;
import pl.mwas.proteana.math.factorials.FactorialFactory;

/**
 *
 * @author loskov
 */
public class Binomial {
    
    private BigDecimal result;
    private int n;
    private int k;
    
    public Binomial(int n, int k) {
        this.n = n;
        this.k = k;
        calculate();
    }
    
    public Binomial(BigDecimal n, BigDecimal k) {
        this(n.intValue(), k.intValue());
    }
    
    private BigDecimal calculate() {
        BigDecimal nFact = new FactorialFactory().getFactorial(n).getResult();
        BigDecimal kFact = new FactorialFactory().getFactorial(k).getResult();
        BigDecimal nkFact = new FactorialFactory().getFactorial(n-k).getResult();
        
        result = nFact.divide(kFact.multiply(nkFact), RoundingMode.CEILING);
        return result;
    }

    public BigDecimal getResult() {
        return result;
    }
}
